package dao

import (
	"zk2/globals"
	"zk2/internal/dto"
	"zk2/internal/models"
)

type UserDao struct {
}

func NewUserDao() *UserDao {
	return &UserDao{}
}

func (u *UserDao) FindUserByMobile(req dto.RegisterReq) (users models.User, err error) {
	db := globals.DB
	err = db.Debug().Where("mobile=?", req.Mobile).First(&users).Error
	return users, err
}

func (u *UserDao) UserAdd(user *models.User) error {

	db := globals.DB
	return db.Debug().Create(user).Error

}
func (u *UserDao) Login(req dto.LoginReq) (users models.User, err error) {
	db := globals.DB
	err = db.Debug().Where("mobile=? and password=?", req.Mobile, req.Password).First(&users).Error
	return users, err
}
